package com.wmw.entity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Page {
	/*
	 * 
	 */
	public List rows = new ArrayList();
	private int showCount = 10; // 每页显示记录数
	private int totalPage = 0; // 总页数
	public int total = 0;// 总记录数
	public int page = 0;// 当前页
	private int currentResult = 0; // 当前记录起始索引
	private boolean entityOrField = false; // true:需要分页的地方，传入的参数就是Page实体；false:需要分页的地方，传入的参数所代表的实体拥有Page属性

	private String sortField = ""; // 排序字段
	private String sortOrder = "asc";// 升序或降序 asc/desc
	
	private Map search = new HashMap(); //查询条件
	
	//public List returnResult = new LinkedList(); 
	
	public int getTotalPage() {
		
		totalPage = (total%showCount==0?total/showCount:total/showCount+1);
		
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public List getRows() {
		return rows;
	}

	public void setRows(List rows) {
		this.rows = rows;
	}

	public int getShowCount() {
		return showCount;
	}

	public void setShowCount(int showCount) {
		this.showCount = showCount;
	}

	public int getPage() {
		if (page <= 0)
			page = 1;
		if (page > getTotalPage())
			page = getTotalPage();
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public int getCurrentResult() {
		currentResult = (getPage() - 1) * getShowCount();
		if (currentResult < 0)
			currentResult = 0;
		return currentResult;
	}

	public void setCurrentResult(int currentResult) {
		this.currentResult = currentResult;
	}

	public boolean isEntityOrField() {
		return entityOrField;
	}

	public void setEntityOrField(boolean entityOrField) {
		this.entityOrField = entityOrField;
	}

	public String getSortField() {
		return sortField;
	}

	public void setSortField(String sortField) {
		this.sortField = sortField;
	}

	public String getSortOrder() {
		return sortOrder;
	}

	public void setSortOrder(String sortOrder) {
		if(sortOrder!=null){
			// 判断一下，防止sql注入
			if(sortOrder.equalsIgnoreCase("desc")){
				this.sortOrder = sortOrder;
			}
		}
	}

	public Map getSearch() {
		return search;
	}

	public void setSearch(Map search) {
		this.search = search;
	}

	
}
